//-----------------------------------------------------------------------
// <copyright file="Null.cs" company="tuliprules.org">
//     Copyright (c) 2010 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the Null class.</summary>
//-----------------------------------------------------------------------

namespace Tulip.Engine.Tuples
{
    using System;

    /// <summary>
    /// Represents a null.   This class is used during tuple member evaluation.
    /// </summary>
    internal class Null : IComparable
    {
        #region IComparable Members

        /// <summary>
        /// Tests to see if two NULL objects provided are equal.
        /// </summary>
        /// <param name="nullA">First null.</param>
        /// <param name="nullB">Second null.</param>
        /// <returns>True if equal.  Otherwise false.</returns>
        public static bool operator ==(Null nullA, Null nullB)
        {
            return !nullA.Equals(null) && nullA.Equals(nullB);
        }

        /// <summary>
        /// Tests to see if two NULL objects provided are not equal.
        /// </summary>
        /// <param name="nullA">First null.</param>
        /// <param name="nullB">Second null.</param>
        /// <returns>True if unequal.  Otherwise false.</returns>
        public static bool operator !=(Null nullA, Null nullB)
        {
            if (nullA.Equals(null))
            {
                return true;
            }

            return !nullA.Equals(nullB);
        }

        /// <summary>
        /// LT operator.
        /// </summary>
        /// <param name="nullA">First null.</param>
        /// <param name="nullB">Second null.</param>
        /// <returns>
        /// True or false.   For two identical NULLs, this is arbitary,
        /// as NULLs never equate.
        /// </returns>
        public static bool operator >(Null nullA, Null nullB)
        {
            if (nullA.Equals(nullB))
            {
                return false;
            }

            return nullA.GetHashCode() > nullB.GetHashCode();
        }

        /// <summary>
        /// GT operator.
        /// </summary>
        /// <param name="nullA">First null.</param>
        /// <param name="nullB">Second null.</param>
        /// <returns>
        /// True or false.   For two identical NULLs, this is arbitary,
        /// as NULLs never equate.
        /// </returns>
        public static bool operator <(Null nullA, Null nullB)
        {
            if (nullA.Equals(nullB))
            {
                return false;
            }

            return nullA.GetHashCode() < nullB.GetHashCode();
        }

        /// <summary>
        /// Camprison method.
        /// </summary>
        /// <param name="obj">Object to be compared.</param>
        /// <returns>Returns 0 if the compared object is a Null.   Otherwise, always return a negative number.</returns>
        public int CompareTo(object obj)
        {
            return (obj is Null) ? 0 : -1;
        }

        /// <summary>
        /// Tests to see if the object provided is equal to this Null.
        /// </summary>
        /// <param name="obj">The object to compare.</param>
        /// <returns>True if equal, otherwise false.</returns>
        public override bool Equals(object obj)
        {
            // Two Null objects are never equal
            return false;
        }

        /// <summary>
        /// Returns the hashcode for the Null.
        /// </summary>
        /// <returns>A hashcode.</returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        #endregion
    }
}